home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C13 / PStashTest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1003 b   |  36 lines

  1. //: C13:PStashTest.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. //{L} PStash
  7. // Test of pointer Stash
  8. #include "PStash.h"
  9. #include "../require.h"
  10. #include <iostream>
  11. #include <fstream>
  12. #include <string>
  13. using namespace std;
  14.  
  15. int main() {
  16.   PStash intStash;
  17.   // 'new' works with built-in types, too. Note
  18.   // the "pseudo-constructor" syntax:
  19.   for(int i = 0; i < 25; i++)
  20.     intStash.add(new int(i));
  21.   for(int u = 0; u < intStash.count(); u++)
  22.     cout << "intStash[" << u << "] = "
  23.          << *(int*)intStash[u] << endl;
  24.  
  25.   ifstream infile("PStashTest.cpp");
  26.   assure(infile, "PStashTest.cpp");
  27.   PStash stringStash;
  28.   string line;
  29.   while(getline(infile, line))
  30.     stringStash.add(new string(line));
  31.   // Print out the strings:
  32.   for(int v = 0; stringStash[v]; v++)
  33.     cout << "stringStash[" << v << "] = "
  34.          << *(string*)stringStash[v] << endl;
  35. } ///:~
  36.